package com.qianxp.authorize.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qianxp.authorize.entity.Function;
import com.qianxp.authorize.entity.Role;
import com.qianxp.authorize.entity.User;
import com.qianxp.authorize.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {
    @Select("select r.* from role r inner join user_role ur on r.id = ur.roleid where ur.userid = #{user.id}")
    List<Role> getRoles(@Param("user") User user);

    @Select("select f.* from sfunction f inner join role_function rf on f.id = rf.functionid inner join user_role ur on ur.roleid = rf.roleid where ur.userid = #{user.id}")
    List<Function> getFunctions(@Param("user") User user);
    @Select("select u.* , r.* from user u " +
            "inner join user_role ur on u.id = ur.userid" +
            "inner join role r on r.id = ur.roleid where ur.userid = #{user.id}")
    UserVO getUserInfo(@Param("user") User user);
}
